package com.ruoyi.order.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.order.domain.Approval;
import com.ruoyi.order.service.IApprovalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;

/**
 * 钉钉审批流程信息Controller
 * 
 * @author ruoyi
 * @date 2025-07-03
 */
@RestController
@RequestMapping("/approval")
public class ApprovalController extends BaseController
{
    @Autowired
    private IApprovalService approvalService;

    /**
     * 查询钉钉审批流程信息列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Approval approval)
    {
        startPage();
        List<Approval> list = approvalService.selectApprovalList(approval);
        return getDataTable(list);
    }

    /**
     * 导出钉钉审批流程信息列表
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, Approval approval)
    {
        List<Approval> list = approvalService.selectApprovalList(approval);
        ExcelUtil<Approval> util = new ExcelUtil<Approval>(Approval.class);
        util.exportExcel(response, list, "钉钉审批流程信息数据");
    }

    /**
     * 获取钉钉审批流程信息详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(approvalService.selectApprovalById(id));
    }

    /**
     * 新增钉钉审批流程信息
     */
    @PostMapping
    public AjaxResult add(@RequestBody Approval approval)
    {
        return toAjax(approvalService.insertApproval(approval));
    }

    /**
     * 修改钉钉审批流程信息
     */

    @PutMapping
    public AjaxResult edit(@RequestBody Approval approval)
    {
        return toAjax(approvalService.updateApproval(approval));
    }

    /**
     * 删除钉钉审批流程信息
     */
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(approvalService.deleteApprovalByIds(ids));
    }
}
